

#include "audio_decoder.hpp"
#include <asm-generic/errno-base.h>
#include <libavutil/error.h>

extern "C" {

    #include <libavcodec/codec.h>
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
    #include <libavutil/frame.h>
    #include <libavcodec/avcodec.h>
    #include <libavcodec/packet.h>
}

int ProcessPacketMessage(AVCodecContext * codec_ctx, AVPacket * packet, AVFrame * frame) {

    int result = avcodec_send_packet(codec_ctx, packet);
    while (result >= 0) {

        result = avcodec_receive_frame(codec_ctx, frame);
        if (result < 0) {

            if (AVERROR(result) == EAGAIN || result == AVERROR_EOF) {

                result = 0;
                break;
            } else {

                result = -1;
                break;
            }
        }
        // process frame data
    }
    return result;
}
